{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['/home/tiendat/transformer-entropy-ids/../', '/home/tiendat/transformer-entropy-ids/notebooks', '/home/tiendat/miniconda3/envs/torchtf/lib/python39.zip', '/home/tiendat/miniconda3/envs/torchtf/lib/python3.9', '/home/tiendat/miniconda3/envs/torchtf/lib/python3.9/lib-dynload', '', '/home/tiendat/miniconda3/envs/torchtf/lib/python3.9/site-packages', '../']\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "import os\n",
    "\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "sys.path.append('../')\n",
    "sys.path.insert(0, os.path.dirname(os.getcwd()) + \"/../\")\n",
    "\n",
    "print(sys.path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-12-28 17:02:14.596352: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
      "2023-12-28 17:02:14.648609: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
      "To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
      "2023-12-28 17:02:15.385289: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n",
      "/home/tiendat/miniconda3/envs/torchtf/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n",
      "2023-12-28 17:02:16,510\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "# import vaex\n",
    "import numpy as np\n",
    "import glob\n",
    "import dask.dataframe as dd\n",
    "import json\n",
    "from sklearn.model_selection import train_test_split\n",
    "import math\n",
    "import csv\n",
    "from sklearn.metrics import accuracy_score, recall_score, f1_score, precision_score, classification_report, confusion_matrix\n",
    "import time\n",
    "import _warnings\n",
    "import tensorflow as tf\n",
    "from tqdm import tqdm\n",
    "import swifter\n",
    "import argparse\n",
    "import helper_functions\n",
    "from importlib import reload"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/tiendat/transformer-entropy-ids/road/attacks\n"
     ]
    }
   ],
   "source": [
    "os.chdir(os.path.dirname(os.getcwd()) + \"/road/attacks\")\n",
    "# os.chdir(os.path.dirname(os.getcwd()) + \"/road/ambient\")\n",
    "print(os.getcwd())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Process ROAD log datasets into CSV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_all_data(attack_dict):\n",
    "    df_aggregation = []\n",
    "    \n",
    "    for attack_name, metadata in attack_dict.items():    \n",
    "        if \"accelerator\" not in attack_name and \"metadata\" not in attack_name:\n",
    "            print(f\"{attack_name}\")\n",
    "            file_name = '/home/tiendat/transformer-entropy-ids/road/attacks/{}.log'.format(attack_name)\n",
    "            df_attack = helper_functions.make_can_df(file_name)\n",
    "            df_attack = helper_functions.add_time_diff_per_aid_col(df_attack)\n",
    "            # print(df_attack.shape)\n",
    "            # print(df.dtypes)\n",
    "            df_aggregation.append(df_attack)\n",
    "            print(f\"Finish preprocess {file_name}\")\n",
    "    return df_aggregation\n",
    "\n",
    "def get_time_interval(attack_dict):\n",
    "    attack_metadata = []\n",
    "    \n",
    "    for attack_name, metadata in attack_dict.items():    \n",
    "        if \"accelerator\" not in attack_name and \"metadata\" not in attack_name:\n",
    "            print(f\"Finish get time interval of {attack_name}\")\n",
    "            \n",
    "            # From metadata file\n",
    "            attack_metadata.append([tuple(attack_dict[attack_name][\"injection_interval\"])])\n",
    "    return attack_metadata\n",
    "\n",
    "def mark_label(df_aggregation, attack_metadata, attack_dict):\n",
    "    count = 0\n",
    "    for attack_name, metadata in attack_dict.items():    \n",
    "        if \"accelerator\" not in attack_name and \"metadata\" not in attack_name:\n",
    "            print(f\"Index {count}: {attack_name} --- {attack_dict[attack_name]['injection_id']}\")\n",
    "            \n",
    "            if attack_dict[attack_name][\"injection_id\"] != \"XXX\":\n",
    "                df_aggregation[count] = helper_functions.add_actual_attack_col(df_aggregation[count], attack_metadata[count], int(attack_dict[attack_name][\"injection_id\"], 16), attack_dict[attack_name][\"injection_data_str\"], attack_name)\n",
    "                print(len(df_aggregation[count][df_aggregation[count]['label'] == True]['label']))\n",
    "                print(len(df_aggregation[count][df_aggregation[count]['label'] == False]['label']))\n",
    "            else:\n",
    "                df_aggregation[count] = helper_functions.add_actual_attack_col(df_aggregation[count], attack_metadata[count], \"XXX\", attack_dict[attack_name][\"injection_data_str\"], attack_name)\n",
    "                print(len(df_aggregation[count][df_aggregation[count]['label'] == True]['label']))\n",
    "                print(len(df_aggregation[count][df_aggregation[count]['label'] == False]['label']))\n",
    "            count += 1\n",
    "    return df_aggregation\n",
    "\n",
    "def filter_attack(arr, keyword):\n",
    "    sub_array = []\n",
    "    for item in arr:\n",
    "        if keyword in item:\n",
    "            sub_array.append(item)\n",
    "    return sub_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "correlated_signal_attack_1\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/correlated_signal_attack_1.log\n",
      "correlated_signal_attack_1_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/correlated_signal_attack_1_masquerade.log\n",
      "correlated_signal_attack_2\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/correlated_signal_attack_2.log\n",
      "correlated_signal_attack_2_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/correlated_signal_attack_2_masquerade.log\n",
      "correlated_signal_attack_3\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/correlated_signal_attack_3.log\n",
      "correlated_signal_attack_3_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/correlated_signal_attack_3_masquerade.log\n",
      "fuzzing_attack_1\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/fuzzing_attack_1.log\n",
      "fuzzing_attack_2\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/fuzzing_attack_2.log\n",
      "fuzzing_attack_3\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/fuzzing_attack_3.log\n",
      "max_engine_coolant_temp_attack\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/max_engine_coolant_temp_attack.log\n",
      "max_engine_coolant_temp_attack_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/max_engine_coolant_temp_attack_masquerade.log\n",
      "max_speedometer_attack_1\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/max_speedometer_attack_1.log\n",
      "max_speedometer_attack_1_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/max_speedometer_attack_1_masquerade.log\n",
      "max_speedometer_attack_2\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/max_speedometer_attack_2.log\n",
      "max_speedometer_attack_2_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/max_speedometer_attack_2_masquerade.log\n",
      "max_speedometer_attack_3\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/max_speedometer_attack_3.log\n",
      "max_speedometer_attack_3_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/max_speedometer_attack_3_masquerade.log\n",
      "reverse_light_off_attack_1\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_off_attack_1.log\n",
      "reverse_light_off_attack_1_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_off_attack_1_masquerade.log\n",
      "reverse_light_off_attack_2\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_off_attack_2.log\n",
      "reverse_light_off_attack_2_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_off_attack_2_masquerade.log\n",
      "reverse_light_off_attack_3\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_off_attack_3.log\n",
      "reverse_light_off_attack_3_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_off_attack_3_masquerade.log\n",
      "reverse_light_on_attack_1\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_on_attack_1.log\n",
      "reverse_light_on_attack_1_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_on_attack_1_masquerade.log\n",
      "reverse_light_on_attack_2\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_on_attack_2.log\n",
      "reverse_light_on_attack_2_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_on_attack_2_masquerade.log\n",
      "reverse_light_on_attack_3\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_on_attack_3.log\n",
      "reverse_light_on_attack_3_masquerade\n",
      "Finish preprocess /home/tiendat/transformer-entropy-ids/road/attacks/reverse_light_on_attack_3_masquerade.log\n",
      "Finish get time interval of correlated_signal_attack_1\n",
      "Finish get time interval of correlated_signal_attack_1_masquerade\n",
      "Finish get time interval of correlated_signal_attack_2\n",
      "Finish get time interval of correlated_signal_attack_2_masquerade\n",
      "Finish get time interval of correlated_signal_attack_3\n",
      "Finish get time interval of correlated_signal_attack_3_masquerade\n",
      "Finish get time interval of fuzzing_attack_1\n",
      "Finish get time interval of fuzzing_attack_2\n",
      "Finish get time interval of fuzzing_attack_3\n",
      "Finish get time interval of max_engine_coolant_temp_attack\n",
      "Finish get time interval of max_engine_coolant_temp_attack_masquerade\n",
      "Finish get time interval of max_speedometer_attack_1\n",
      "Finish get time interval of max_speedometer_attack_1_masquerade\n",
      "Finish get time interval of max_speedometer_attack_2\n",
      "Finish get time interval of max_speedometer_attack_2_masquerade\n",
      "Finish get time interval of max_speedometer_attack_3\n",
      "Finish get time interval of max_speedometer_attack_3_masquerade\n",
      "Finish get time interval of reverse_light_off_attack_1\n",
      "Finish get time interval of reverse_light_off_attack_1_masquerade\n",
      "Finish get time interval of reverse_light_off_attack_2\n",
      "Finish get time interval of reverse_light_off_attack_2_masquerade\n",
      "Finish get time interval of reverse_light_off_attack_3\n",
      "Finish get time interval of reverse_light_off_attack_3_masquerade\n",
      "Finish get time interval of reverse_light_on_attack_1\n",
      "Finish get time interval of reverse_light_on_attack_1_masquerade\n",
      "Finish get time interval of reverse_light_on_attack_2\n",
      "Finish get time interval of reverse_light_on_attack_2_masquerade\n",
      "Finish get time interval of reverse_light_on_attack_3\n",
      "Finish get time interval of reverse_light_on_attack_3_masquerade\n",
      "Index 0: correlated_signal_attack_1 --- 0x6e0\n",
      "2087\n",
      "74044\n",
      "Index 1: correlated_signal_attack_1_masquerade --- 0x6e0\n",
      "2087\n",
      "71958\n",
      "Index 2: correlated_signal_attack_2 --- 0x6e0\n",
      "2141\n",
      "63152\n",
      "Index 3: correlated_signal_attack_2_masquerade --- 0x6e0\n",
      "2141\n",
      "61012\n",
      "Index 4: correlated_signal_attack_3 --- 0x6e0\n",
      "1265\n",
      "37896\n",
      "Index 5: correlated_signal_attack_3_masquerade --- 0x6e0\n",
      "1265\n",
      "36632\n",
      "Index 6: fuzzing_attack_1 --- XXX\n",
      "36\n",
      "45549\n",
      "Index 7: fuzzing_attack_2 --- XXX\n",
      "16\n",
      "29857\n",
      "Index 8: fuzzing_attack_3 --- XXX\n",
      "4\n",
      "12181\n",
      "Index 9: max_engine_coolant_temp_attack --- 0x4e7\n",
      "43\n",
      "57870\n",
      "Index 10: max_engine_coolant_temp_attack_masquerade --- 0x4e7\n",
      "43\n",
      "57828\n",
      "Index 11: max_speedometer_attack_1 --- 0xd0\n",
      "2460\n",
      "197541\n",
      "Index 12: max_speedometer_attack_1_masquerade --- 0xd0\n",
      "2445\n",
      "195112\n",
      "Index 13: max_speedometer_attack_2 --- 0xd0\n",
      "3170\n",
      "133603\n",
      "Index 14: max_speedometer_attack_2_masquerade --- 0xd0\n",
      "3141\n",
      "130492\n",
      "Index 15: max_speedometer_attack_3 --- 0xd0\n",
      "6127\n",
      "194215\n",
      "Index 16: max_speedometer_attack_3_masquerade --- 0xd0\n",
      "6108\n",
      "188127\n",
      "Index 17: reverse_light_off_attack_1 --- 0xd0\n",
      "673\n",
      "62874\n",
      "Index 18: reverse_light_off_attack_1_masquerade --- 0xd0\n",
      "673\n",
      "62202\n",
      "Index 19: reverse_light_off_attack_2 --- 0xd0\n",
      "2378\n",
      "91008\n",
      "Index 20: reverse_light_off_attack_2_masquerade --- 0xd0\n",
      "2372\n",
      "88643\n",
      "Index 21: reverse_light_off_attack_3 --- 0xd0\n",
      "2435\n",
      "129576\n",
      "Index 22: reverse_light_off_attack_3_masquerade --- 0xd0\n",
      "2435\n",
      "127142\n",
      "Index 23: reverse_light_on_attack_1 --- 0xd0\n",
      "3269\n",
      "121580\n",
      "Index 24: reverse_light_on_attack_1_masquerade --- 0xd0\n",
      "1992\n",
      "120866\n",
      "Index 25: reverse_light_on_attack_2 --- 0xd0\n",
      "3754\n",
      "161211\n",
      "Index 26: reverse_light_on_attack_2_masquerade --- 0xd0\n",
      "3690\n",
      "157586\n",
      "Index 27: reverse_light_on_attack_3 --- 0xd0\n",
      "2292\n",
      "143956\n",
      "Index 28: reverse_light_on_attack_3_masquerade --- 0xd0\n",
      "2291\n",
      "141606\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>aid</th>\n",
       "      <th>data</th>\n",
       "      <th>time_diffs</th>\n",
       "      <th>label</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3873</th>\n",
       "      <td>1.618163</td>\n",
       "      <td>6</td>\n",
       "      <td>0800006400000000</td>\n",
       "      <td>0.999845</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6266</th>\n",
       "      <td>2.618064</td>\n",
       "      <td>6</td>\n",
       "      <td>0800006400000000</td>\n",
       "      <td>0.999901</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8655</th>\n",
       "      <td>3.617806</td>\n",
       "      <td>6</td>\n",
       "      <td>0800006400000000</td>\n",
       "      <td>0.999742</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11049</th>\n",
       "      <td>4.617810</td>\n",
       "      <td>6</td>\n",
       "      <td>0800006400000000</td>\n",
       "      <td>1.000004</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13441</th>\n",
       "      <td>5.618164</td>\n",
       "      <td>6</td>\n",
       "      <td>0800006400000000</td>\n",
       "      <td>1.000354</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80160</th>\n",
       "      <td>32.636582</td>\n",
       "      <td>1788</td>\n",
       "      <td>00000738D2B85800</td>\n",
       "      <td>0.099969</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80402</th>\n",
       "      <td>32.736450</td>\n",
       "      <td>1788</td>\n",
       "      <td>0000073732B86000</td>\n",
       "      <td>0.099868</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80641</th>\n",
       "      <td>32.836612</td>\n",
       "      <td>1788</td>\n",
       "      <td>0000073892B86800</td>\n",
       "      <td>0.100162</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80874</th>\n",
       "      <td>32.936532</td>\n",
       "      <td>1788</td>\n",
       "      <td>00000737B2B87000</td>\n",
       "      <td>0.099920</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81111</th>\n",
       "      <td>33.036464</td>\n",
       "      <td>1788</td>\n",
       "      <td>00000738B2B87800</td>\n",
       "      <td>0.099932</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>76131 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            time   aid              data  time_diffs  label\n",
       "3873    1.618163     6  0800006400000000    0.999845  False\n",
       "6266    2.618064     6  0800006400000000    0.999901  False\n",
       "8655    3.617806     6  0800006400000000    0.999742  False\n",
       "11049   4.617810     6  0800006400000000    1.000004  False\n",
       "13441   5.618164     6  0800006400000000    1.000354  False\n",
       "...          ...   ...               ...         ...    ...\n",
       "80160  32.636582  1788  00000738D2B85800    0.099969  False\n",
       "80402  32.736450  1788  0000073732B86000    0.099868  False\n",
       "80641  32.836612  1788  0000073892B86800    0.100162  False\n",
       "80874  32.936532  1788  00000737B2B87000    0.099920  False\n",
       "81111  33.036464  1788  00000738B2B87800    0.099932  False\n",
       "\n",
       "[76131 rows x 5 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with open(\"/home/tiendat/transformer-entropy-ids/road/attacks/capture_metadata.json\", \"r\") as read_file:\n",
    "    attack_dict = json.load(read_file)\n",
    "\n",
    "# display(attack_dict)\n",
    "\n",
    "df_aggregation = get_all_data(attack_dict)\n",
    "attack_metadata = get_time_interval(attack_dict)\n",
    "df_aggregation = mark_label(df_aggregation, attack_metadata, attack_dict)\n",
    "\n",
    "display(df_aggregation[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saving correlated_signal_attack_1_dataset.csv\n",
      "Saving correlated_signal_attack_1_masquerade_dataset.csv\n",
      "Saving correlated_signal_attack_2_dataset.csv\n",
      "Saving correlated_signal_attack_2_masquerade_dataset.csv\n",
      "Saving correlated_signal_attack_3_dataset.csv\n",
      "Saving correlated_signal_attack_3_masquerade_dataset.csv\n",
      "Saving fuzzing_attack_1_dataset.csv\n",
      "Saving fuzzing_attack_2_dataset.csv\n",
      "Saving fuzzing_attack_3_dataset.csv\n",
      "Saving max_engine_coolant_temp_attack_dataset.csv\n",
      "Saving max_engine_coolant_temp_attack_masquerade_dataset.csv\n",
      "Saving max_speedometer_attack_1_dataset.csv\n",
      "Saving max_speedometer_attack_1_masquerade_dataset.csv\n",
      "Saving max_speedometer_attack_2_dataset.csv\n",
      "Saving max_speedometer_attack_2_masquerade_dataset.csv\n",
      "Saving max_speedometer_attack_3_dataset.csv\n",
      "Saving max_speedometer_attack_3_masquerade_dataset.csv\n",
      "Saving reverse_light_off_attack_1_dataset.csv\n",
      "Saving reverse_light_off_attack_1_masquerade_dataset.csv\n",
      "Saving reverse_light_off_attack_2_dataset.csv\n",
      "Saving reverse_light_off_attack_2_masquerade_dataset.csv\n",
      "Saving reverse_light_off_attack_3_dataset.csv\n",
      "Saving reverse_light_off_attack_3_masquerade_dataset.csv\n",
      "Saving reverse_light_on_attack_1_dataset.csv\n",
      "Saving reverse_light_on_attack_1_masquerade_dataset.csv\n",
      "Saving reverse_light_on_attack_2_dataset.csv\n",
      "Saving reverse_light_on_attack_2_masquerade_dataset.csv\n",
      "Saving reverse_light_on_attack_3_dataset.csv\n",
      "Saving reverse_light_on_attack_3_masquerade_dataset.csv\n"
     ]
    }
   ],
   "source": [
    "count = 0\n",
    "out_mas = '/home/tiendat/transformer-entropy-ids/road/mas_dataset/'\n",
    "out_fab = '/home/tiendat/transformer-entropy-ids/road/fab_dataset/'\n",
    "for attack_name, metadata in attack_dict.items():\n",
    "    if \"accelerator\" not in attack_name and \"metadata\" not in attack_name:\n",
    "        print(f\"Saving {attack_name}_dataset.csv\")\n",
    "        if \"masquerade\" not in attack_name:\n",
    "            foutput = '{}/{}_dataset.csv'.format(out_fab, attack_name)\n",
    "            df_aggregation[count].to_csv(foutput, index=False)\n",
    "        else:\n",
    "            foutput = '{}/{}_dataset.csv'.format(out_mas, attack_name)\n",
    "            df_aggregation[count].to_csv(foutput, index=False)\n",
    "        count += 1\n",
    "        "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "piptorchtf",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.17"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
